package code.Frame.EPFrame;

import code.Frame.FrameManager;
import code.MYSQL;
import code.Main;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class historyFrame {
    public JPanel panel;
    private JLabel title;
    private JTable info;
    private JButton back;

    private int sid;

    public historyFrame() {
        back.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                Main.frame.remove(Main.panel_now);
                Main.panel_now = FrameManager.ep_shop;
                Main.frame.setContentPane(Main.panel_now);
                Main.panel_now.revalidate();
            }
        });
    }

    public void set_sid(int id)
    {
        sid = id;
    }

    public void refresh_table()
    {
        String[] colNames = {"OID", "描述", "总价", "创建时间"};
        String[][] data;
        try
        {
            data = MYSQL.query_shop_order(sid);
        } catch (SQLException ex)
        {
            throw new RuntimeException(ex);
        }
        DefaultTableModel model = new DefaultTableModel(data, colNames);
        info.setModel(model);
    }
}
